function nextSlide(){
    new Ajax.Request(nex_url, {
      method: 'get',
      asynchronous:false
    });
}

function prevSlide(){
    new Ajax.Request(pre_url, {
      method: 'get',
      asynchronous:false
    });
}

function toggleRun() {
    $('run_link').toggle();
    $('touch_area').toggle();
    $('stopButton').toggle();
}

function changeTitle(title){
    $('pageTitle').update(title);
}

var downPoint = {x:-1, y:-1}

function initTouch(){
    $('touch_area').addEventListener ('touchstart', touchStartHandler, false);
    $('touch_area').addEventListener ('touchmove', touchMoveHandler, false)
}

function touchStartHandler(event){
    event.preventDefault ();
    downPoint.x = event.targetTouches[0].clientX
    downPoint.y = event.targetTouches[0].clientY
}

function touchMoveHandler(event){
   event.preventDefault ();
   if (downPoint.x == -1) return;
   var upPoint = {}
   upPoint.x = event.targetTouches[0].clientX
   upPoint.y = event.targetTouches[0].clientY
   if (upPoint.x < downPoint.x &&
       (downPoint.x - upPoint.x)*(downPoint.x - upPoint.x)+
       (downPoint.y - upPoint.y)*(downPoint.y - upPoint.y) > 100) {
       nextSlide();
   }
   if (upPoint.x >= downPoint.x &&
        (downPoint.x - upPoint.x)*(downPoint.x - upPoint.x)+
        (downPoint.y - upPoint.y)*(downPoint.y - upPoint.y) > 100)  {
        prevSlide();
    }
    downPoint.x = -1;
    downPoint.y = -1;
}